package com.hongdee.crm.remindClose.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.common.util.EntityUtils;
import com.hongdee.crm.remindClose.entity.TCrmCarRemindClose;
import com.hongdee.crm.remindClose.service.ITCrmCarRemindCloseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 名  称:TCrmCarRemindCloseController
 * 类  型:class
 * 描  述:
 * 路  径:com.hongdee.crm.remindClose.controller
 * 作  者: 术洪超
 * 日  期:2017-03-21 09:43
 */

@RestController
@RequestMapping("/crm/remindClose")
public class TCrmCarRemindCloseController {

    @Autowired
    private ITCrmCarRemindCloseService itCrmCarRemindCloseService;


    /**
     * @param uid      登录用户 ID
     * @param token    登录用户 Token
     * @param start    起始记录
     * @param limit    页面大小
     * @param plateNum 车牌号
     * @param vin      车架号
     * @return Map
     * @throws Exception
     * @desc 通过 JDBCDao分页查询
     * @author 术洪超
     */
    @RequestMapping("/closePage")
    @ResponseBody
    public Map closePage(@RequestParam(name = "uid", defaultValue = "") String uid,
                         @RequestParam(name = "token", defaultValue = "") String token,
                         @RequestParam(name = "start", defaultValue = "0") String start,
                         @RequestParam(name = "limit", defaultValue = "50") String limit,
                         @RequestParam(name = "plateNum", defaultValue = "") String plateNum,
                         @RequestParam(name = "pcode", defaultValue = "") String pcode,
                         @RequestParam(name = "code", defaultValue = "") String code,
                         @RequestParam(name = "vin", defaultValue = "")String vin,
                         @RequestParam(name = "carId", defaultValue = "")String carId) throws Exception {

        Map map = itCrmCarRemindCloseService.closePage(start, limit, uid, plateNum, vin, carId,pcode,code);
        map.put("success", true);
        map.put("msg", "已关闭车辆分页查询成功！");
        return map;
    }


    /**
     * @param uid      登录用户 ID
     * @param token    登录用户 Token
     * @param start    起始记录
     * @param limit    页面大小
     * @param plateNum 车牌号
     * @param vin      车架号
     * @return Map
     * @throws Exception
     * @desc 通过 JDBCDao分页查询
     * @author 术洪超
     */
    @RequestMapping("/carPage")
    @ResponseBody
    public Map carPage(@RequestParam(name = "uid", defaultValue = "") String uid,
                       @RequestParam(name = "token", defaultValue = "") String token,
                       @RequestParam(name = "start", defaultValue = "0") String start,
                       @RequestParam(name = "limit", defaultValue = "50") String limit,
                       @RequestParam(name = "plateNum", defaultValue = "") String plateNum,
                       @RequestParam(name = "vin", defaultValue = "") String vin,
                       @RequestParam(name = "typePcode", defaultValue = "") String typePcode,
                       @RequestParam(name = "typeCode", defaultValue = "") String typeCode
    ) throws Exception {

        Map map = itCrmCarRemindCloseService.carPage(start, limit, uid, plateNum, vin,typePcode,typeCode);
        map.put("success", true);
        map.put("msg", "未关闭车辆分页查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户 ID
     * @param token 登录用户 Token
     * @param data  要保存的关闭提醒实体
     * @return ResultEntity
     * @throws Exception
     * @desc
     * @author 术洪超
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultEntity save(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestBody TCrmCarRemindClose data) throws Exception {
        EntityUtils.valid(data);
        TCrmCarRemindClose rc = this.itCrmCarRemindCloseService.save(data, uid);
        ResultEntity res = new ResultEntity();
        res.setMsg("关闭提醒成功！");
        res.setSuccess(true);
        res.setData(rc);
        return res;
    }

    /**
     * @param uid   登录用户 ID
     * @param token 登录用户 Token
     * @param data  要保存的关闭提醒实体
     * @return ResultEntity
     * @throws Exception
     * @desc
     * @author 术洪超
     */
    @RequestMapping("/saveByType")
    @ResponseBody
    public ResultEntity saveByType(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "code", defaultValue = "") String code,
                             @RequestParam(name = "pcode", defaultValue = "") String pcode,
                             @RequestBody List<TCrmCarRemindClose> data) throws Exception {
        EntityUtils.valid(data);
        this.itCrmCarRemindCloseService.saveRemindCloseByTaskType(pcode,code,uid,data);
        ResultEntity res = new ResultEntity();
        res.setMsg("关闭提醒成功！");
        res.setSuccess(true);
        return res;
    }

    /**
     * @param uid   登录用户 ID
     * @param token 登录用户 Token
     * @param id    要删除的提醒实体主键
     * @return ResultEntity
     * @throws Exception
     * @desc ResultEntity
     * @author 术洪超
     */
    @RequestMapping("/del")
    @ResponseBody
    public ResultEntity del(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "id", defaultValue = "") String id,
                            @RequestParam(name = "carId", defaultValue = "") String carId) throws Exception {
        ResultEntity res = new ResultEntity();
        itCrmCarRemindCloseService.del(id, uid,carId);
        res.setSuccess(true);
        res.setMsg("开启提醒成功！");
        return res;
    }


}
